package t20211226;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;

/**
 * @Author: DengJia
 * @Date: 2021/12/26 20:36
 * @Description:
 */

public class LoggingExceptions {

    public static void main(String[] args) {
        try {
            throw new LoggingException();
        } catch (LoggingException e) {
            System.err.println("caught " + e);
        }
    }
}

class LoggingException extends Exception {
    // String参数通常是与错误相关的包名和类名
    private static final Logger logger = Logger.getLogger("LoggingException");

    public LoggingException() {
        StringWriter trace = new StringWriter();
        // 堆栈记录
        printStackTrace(new PrintWriter(trace));
        // 并且在控制台进行打印
        logger.severe(trace.toString());
    }
}
